package com.fzkj.shejimoshi.strategy.factory;

import com.fzkj.shejimoshi.strategy.GiteeUserStrategy;
import com.fzkj.shejimoshi.strategy.GithubUserStrategy;
import com.fzkj.shejimoshi.strategy.QQUserStrategy;
import com.fzkj.shejimoshi.strategy.UserStrategy;

import java.util.ArrayList;
import java.util.List;

/**
 * @DESCRIPTION: TODO 工厂类，用于获取不同策略的返回
 * @AUTHOR: AnotherOne
 * @DATE: 2021/7/16 11:37
 */
public class UserStrategyFactory {

    List<UserStrategy> strategies = new ArrayList(){{
        this.add(new GiteeUserStrategy());
        this.add(new GithubUserStrategy());
        this.add(new QQUserStrategy());
    }};

    /**
     * 通过传入的不同类型获取不同的策略
     * @param type
     * @return
     */
    public UserStrategy getStrategy(String type){
        for (UserStrategy strategy : strategies) {
            if (strategy.supportType().name().equalsIgnoreCase(type))
                return strategy;
        }
        return null;
    }

}
